import "reflect-metadata";
import { UserService } from "./UserService";
import CollectionInstance from "./Collection";

type MyParameterDecorator = (
  target: Object,
  propertyKey?: string | symbol,
  parameterIndex?: number
) => void;
function InjectConstructor(injectid?: string): MyParameterDecorator {
  return (targetClass, paramname, paramindex) => {
    let constructorParamArr = Reflect.getMetadata(
      "design:paramtypes",
      targetClass
    );
    const construcorParamArr = new constructorParamArr[paramindex!]();
    // 外部保存
    CollectionInstance.set(injectid!, construcorParamArr);
  };
}

// 构造器参数装饰器
class UserController {
  constructor(
    @InjectConstructor("userService") private userService?: UserService,
    private count?: string
  ) {}

  public login() {
    let peopleServiceInstance = CollectionInstance.get("userService");
    peopleServiceInstance.login();
  }
}

let userService = new UserController();
userService.login();

export {};
